<template>
  <el-container>
    <el-main class="main">
      <div class="table-main">
        <div class="tableName">{{ tableName }}</div>
        <div class="sub-tableName">
          <div class="time"><span>检查时间：</span>{{ form.createdTime }}</div>
          <div class="No">
            <span>编号：</span>
            <span>{{ form.tableNo || "-" }}</span>
          </div>
        </div>
        <table border="1" cellpadding="0" cellspacing="0" class="table">
          <tr>
            <td class="text">单位名称</td>
            <td colspan="3">
              <el-input
                v-model="form.unitName"
                disabled
                placeholder="单位名称(盖章)"
              />
            </td>
            <td class="text">负 责 人</td>
            <td colspan="2">
              <el-input
                v-model="form.chargePerson"
                disabled
                placeholder="请输入负责人"
              />
            </td>
          </tr>
          <tr>
            <td class="text">单位地址</td>
            <td colspan="3">
              <el-input
                v-model="form.address"
                disabled
                placeholder="请输入单位地址"
              />
            </td>
            <td class="text">邮政编码</td>
            <td colspan="2">
              <el-input v-model="form.code" disabled placeholder="-" />
            </td>
          </tr>
          <tr>
            <td class="text">联 系 人</td>
            <td colspan="3">
              <el-input
                v-model="form.chargePerson"
                disabled
                placeholder="请输入联系人"
              />
            </td>
            <td class="text">联系电话</td>
            <td colspan="2">
              <el-input
                v-model="form.linkTelephone"
                maxlength="11"
                disabled
                placeholder="请输入联系电话"
              />
            </td>
          </tr>
          <tr>
            <td class="text">单位基本概况</td>
            <td colspan="5">
              <el-input
                v-model="form.jbqk"
                type="textarea"
                disabled
                placeholder="请输入单位基本概况"
              />
            </td>
          </tr>
          <tr>
            <td rowspan="14" class="text">防雷安全责任制度落实情况</td>
            <td colspan="3" class="text">是否建立防雷安全责任制</td>
            <td colspan="1">
              <el-radio-group
                v-model="form.sfjlflanzrz"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload('是否建立防雷安全责任制', 'sfjlflanzrz', '')
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('sfjlflanzrz')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">是否定期对雷电防护装置进行维护</td>
            <td colspan="1">
              <el-radio-group
                v-model="form.sfdqdldfhzzjxwh"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '是否定期对雷电防护装置进行维护',
                    'sfdqdldfhzzjxwh',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('sfdqdldfhzzjxwh')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">是否将防雷安全纳入应急管理</td>
            <td colspan="1">
              <el-radio-group
                v-model="form.sfjflaqnryjgl"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '是否将防雷安全纳入应急管理',
                    'sfjflaqnryjgl',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('sfjflaqnryjgl')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">是否建立防雷安全工作档案</td>
            <td colspan="1">
              <el-radio-group
                v-model="form.sfjlflaqgzda"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload('是否建立防雷安全工作档案', 'sfjlflaqgzda', '')
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('sfjlflaqgzda')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">
              是否按要求配备专（兼）防雷安全管理员
            </td>
            <td colspan="1">
              <el-radio-group
                v-model="form.sfayjpbangly"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '是否按要求配备专（兼）防雷安全管理员',
                    'sfayjpbangly',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('sfayjpbangly')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">是否对防雷安全存在问题进行整改</td>
            <td colspan="1">
              <el-radio-group
                v-model="form.sfdflanczwtjxxg"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '是否对防雷安全存在问题进行整改',
                    'sfdflanczwtjxxg',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('sfdflanczwtjxxg')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">是否有进行定期的防雷安全教育</td>
            <td colspan="1">
              <el-radio-group
                v-model="form.sfyjxdqaqjy"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '是否有进行定期的防雷安全教育',
                    'sfyjxdqaqjy',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('sfyjxdqaqjy')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td rowspan="12" class="text">雷电防护装置安全性能状况</td>
            <td colspan="3" class="text">
              各场所是否按照国家防雷技术标准和法规规定安装雷电防护装置
            </td>
            <td colspan="1">
              <el-radio-group
                v-model="form.gcssfazbzazldfhzz"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '各场所是否按照国家防雷技术标准和法规规定安装雷电防护装置',
                    'gcssfazbzazldfhzz',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('gcssfazbzazldfhzz')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="2" rowspan="4" class="text">
              是否委托具有资质的检测机构依法开展每年一次（易燃易爆场所一年两次）雷电防护装置安全性能定期检测
            </td>
            <td class="text">已全部按要求定期检测</td>
            <td class="text">检测时间</td>
            <td>
              <el-date-picker
                v-model="form.ldfhzzJcsj"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetime"
                disabled
                placeholder="选择日期时间"
              />
            </td>
          </tr>
          <tr>
            <td rowspan="2" class="text">部分按要求定期检测</td>
            <td class="text">已检项目数</td>
            <td>
              <el-input
                v-model="form.ldfhzzYjcxms"
                min="0"
                type="number"
                disabled
                placeholder="请输入已检项目数"
              />
            </td>
          </tr>
          <tr>
            <td class="text">未检项目数</td>
            <td>
              <el-input
                v-model="form.ldfhzzWjcxms"
                min="0"
                type="number"
                disabled
                placeholder="请输入未检项目数"
              />
            </td>
          </tr>
          <tr>
            <td colspan="2" class="text">多年未检测</td>
            <td>
              <el-radio-group
                v-model="form.ldfhzzsfdnwjc"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">雷电防护装置定期检测是否全部合格</td>
            <td colspan="1">
              <el-radio-group
                v-model="form.ldfhzzsfqbhg"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '雷电防护装置定期检测是否全部合格',
                    'ldfhzzsfqbhg',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('ldfhzzsfqbhg')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">历史上发生的雷击灾情情况</td>
            <td colspan="1">
              <el-input
                v-model="form.ldfhzzLsljzq"
                disabled
                placeholder="请输入历史上发生的雷击灾情情况"
              />
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload('历史上发生的雷击灾情情况', 'ldfhzzLsljzq', '')
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('ldfhzzLsljzq')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="3" class="text">
              新（改、扩）建项目雷电防护装置是否依法报请设计审核和竣工验收
            </td>
            <td colspan="1">
              <el-radio-group
                v-model="form.ldfhzzsfyfshhys"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </td>
            <td colspan="1" align="center">
              <el-button
                size="small"
                type="primary"
                @click="
                  handleUpload(
                    '新（改、扩）建项目雷电防护装置是否依法报请设计审核和竣工验收',
                    'ldfhzzsfyfshhys',
                    ''
                  )
                "
                >上传附件</el-button
              >
            </td>
          </tr>
          <tr>
            <td colspan="11" class="text">
              <div
                v-for="(item, index) in filterFiles('ldfhzzsfyfshhys')"
                :key="index"
                class="file-list"
              >
                <div
                  v-for="(link, fileIndex) in item.files"
                  :key="fileIndex"
                  class="file"
                >
                  <div class="btn" @click="handleDownload(link)">
                    {{ link | splitName }}
                  </div>
                </div>
                <el-link
                  :underline="false"
                  type="success"
                  @click="handleDelUpload(item.proofId)"
                  >删除</el-link
                >
              </div>
            </td>
          </tr>

          <tr>
            <td class="text">防雷安全存在问题等级</td>
            <td colspan="5">
              <el-radio-group
                v-model="form.lpProblemLevel"
                class="radio-group"
                disabled
              >
                <el-radio :label="0">一级(特大）</el-radio>
                <el-radio :label="1">二级（重大）</el-radio>
                <el-radio :label="2">三级（严重）</el-radio>
                <el-radio :label="3">四级（一般）</el-radio>
              </el-radio-group>
            </td>
          </tr>
          <tr>
            <td class="text">防雷安全存在问题和初步整改计划</td>
            <td colspan="5">
              <el-input
                v-model="form.flaqczwthcbzgjh"
                type="textarea"
                disabled
                placeholder="请输入防雷安全存在问题和初步整改计划"
              />
            </td>
          </tr>
        </table>

        <div class="foot-table">
          <div class="name">
            <span>检查人员（签名）:</span>
            <span>{{ form.rawPersonName }}</span>
          </div>
          <div class="unit">
            <span>被检单位（签名）：</span>
            <span>{{ form.inspectUnitSign }}</span>
          </div>
        </div>
        <div class="search-user-list">
          <el-button @click="$router.push('/uploadFile')">返回</el-button>
        </div>
      </div>

      <el-dialog :visible.sync="showUpload" width="500px" :title="title">
        <div class="upload">
          <el-upload
            :action="actions"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :headers="token"
            :limit="fileLimit"
            :on-exceed="handleExceed"
            :file-list="fileList"
            :on-change="handleChange"
          >
            <el-button size="small" type="primary">选择文件</el-button>
            <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
          </el-upload>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="showUpload = false">取 消</el-button>
          <el-button type="primary" @click="handleFileAdd">确 定</el-button>
        </span>
      </el-dialog>
    </el-main>
  </el-container>
</template>

<script>
import { mapGetters } from "vuex";
import { findByPlanDetailId } from "@/api";
import {
  uploadAdd,
  findInspectProofs,
  findByIdProofs,
  updateProofs,
  deleteListProofs,
} from "./api";
import { getToken } from "@/utils/auth";
export default {
  name: "Sign",
  data() {
    return {
      token: {
        accessToken: getToken(),
      },
      tableName: "衢州市防雷安全检查表",
      form: {
        userId: "",
        unitName: "",
        address: "",
        person: "",
        telephone: "",
        remark: "",
      },
      fileList: [],
      actions: process.env.VUE_APP_BASE_API + `/v1/file/upload`,
      form: {
        lpUnitId: null,
        sfjlflanzrz: 0,
        sfdqdldfhzzjxwh: 0,
        sfjflaqnryjgl: 0,
        sfjlflaqgzda: 0,
        sfayjpbangly: 0,
        sfdflanczwtjxxg: 0,
        sfyjxdqaqjy: 0,
        gcssfazbzazldfhzz: 0,
        ldfhzzJcsj: "",
        ldfhzzYjcxms: null,
        ldfhzzWjcxms: null,
        ldfhzzsfdnwjc: 0,
        ldfhzzsfqbhg: 0,
        ldfhzzLsljzq: "",
        ldfhzzsfyfshhys: 0,
        lpProblemLevel: null,
        flaqczwthcbzgjh: "",
        creator: "",
        createdTime: "",
        inspectUnitSign: "",
        unitName: "",
        rawPersonName: "",
        chargePerson: "",
        linkTelephone: "",
        // plan_id: null,
      },
      // sign_url: "",
      inspectId: "",
      show: true,
      fullscreenLoading: false,
      detailId: "",

      masterJSONString: {
        "cmdb!modelId": "26",
        "cmdb!modelNo": "met_lp_inspect_proof",
        detail_id: null,
        inspect_item: "",
      },
      proof_id: "",
      uploadResponseList: [],
      inspectItem: "",
      fileLimit: 5,
      showUpload: false,
      title: "",
      filesArray: [],
      filesForm: {
        "cmdb!modelNo": "met_lp_inspect_proof",
        file_ids: "",
        file_urls: "",
        masterJSONString: {
          "cmdb!modelId": "26",
          "cmdb!modelNo": "met_lp_inspect_proof",
          detail_id: null,
          inspect_item: "",
          // proof_id: ''
        },
      },
    };
  },
  computed: {
    filterFiles(type) {
      return function inner(type) {
        let dealFiles = [];
        this.uploadResponseList
          .filter((item) => item.inspectItem === type)
          .map((_item) => {
            let dealFilesObj = {
              files: [],
              proofId: "",
            };
            _item.fileUrls.split(",").map((res) => {
              if (res) {
                dealFilesObj.files.push(res);
                dealFilesObj.proofId = _item.proofId;
              }
            });
            dealFiles.push(dealFilesObj);
          });
        return dealFiles;
      };
    },
    ...mapGetters(["userInfo"]),
  },
  filters: {
    splitName(href) {
      const name = href.substring(href.lastIndexOf("/") + 1);
      return name;
    },
  },
  created() {
    const { detailId } = this.$route.query;
    this.masterJSONString.detail_id = detailId;
    this.detailId = detailId;
    this.getInitData(detailId);

    this.getInspectProofs();
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择${this.fileLimit}个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + fileList.length} 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handleChange(file, fileList) {
      // this.fileList
      this.filesArray = [];
      if (fileList.length > 0) {
        fileList.map((item) => {
          if (item.response && item.response.data) {
            this.filesArray.push(item.response.data);
          }
        });
      }
    },

    handleUpload(title, inspect_item, proofId) {
      // if (proofId) {
      //   this.title = title + '资料上传修改'
      //   this.filesForm.masterJSONString.proof_id = proofId
      //   this.findByIdProofsData(proofId)
      // }
      // else
      this.title = title + "资料上传";
      this.inspectItem = inspect_item;
      this.masterJSONString.inspect_item = inspect_item;
      this.showUpload = true;
    },

    handleFileAdd() {
      console.log(
        "🚀 ~ file: upload-table.vue ~ line 413 ~ handleFileAdd ~ this.filesForm.masterJSONString.proof_id",
        this.filesForm
      );
      let ids = this.filesArray.map((item) => item.fileId);
      let urls = this.filesArray.map((item) => item.fileUrl);
      this.filesForm.file_ids = ids.join(",");
      this.filesForm.file_urls = urls.join(",");
      this.filesForm.masterJSONString = JSON.stringify(this.masterJSONString);
      uploadAdd(this.filesForm)
        .then(({ success, message }) => {
          if (success) {
            this.$message.success(message);
            this.getInspectProofs();
            this.showUpload = false;
            this.fileList = [];
            this.fileArray = [];
          } else {
            this.$message.error(message);
          }
        })
        .catch((err) => {});
    },

    findByIdProofsData(proofId) {
      findByIdProofs(proofId)
        .then(({ success, message, data }) => {
          if (success) {
            const { file_urls } = data;
            // this.proof_id = proof_id
            // this.filesForm = {
            //   'cmdb!modelNo': 'met_lp_inspect_proof',
            //   file_ids,
            //   file_urls,
            //   masterJSONString: {
            //     "cmdb!modelId": "26",
            //     "cmdb!modelNo": "met_lp_inspect_proof",
            //     detail_id,
            //     inspect_item,
            //     proof_id
            //   }
            // }
            const fileArray = file_urls.split(",");
            // const fileIds = file_ids.split(',')
            this.fileList = [];
            // this.filesArray = []
            fileArray.map((item, index) => {
              let obj = {};
              // let objb = {}
              if (item) {
                obj.url = item;
                obj.name = item.substring(item.lastIndexOf("/") + 1);
                this.fileList.push(obj);

                // objb.fileName = item.substring(item.lastIndexOf("/") + 1)
                // objb.fileUrl = item
                // objb.fileId = fileIds[index]
                // this.filesArray.push(objb)
              }
            });
            // console.log("🚀 ~ file: upload-table.vue ~ line 465 ~ fileArray.map ~ this.filesArray", this.filesArray)
            // console.log("🚀 ~ file: upload-table.vue ~ line 445 ~ file_urls.split ~ this.fileList", this.fileList)
          } else {
            this.$message.error(message);
          }
        })
        .catch((err) => {});
    },

    // 获取上传信息
    getInspectProofs() {
      // const form = this.inspectItem ? { detailId: this.detailId, inspectItem: this.inspectItem } : { detailId: this.detailId }
      findInspectProofs({ detailId: this.detailId })
        .then(({ data }) => {
          this.uploadResponseList = data;
        })
        .catch((err) => {
          console.log(
            "🚀 ~ file: sign.vue ~ line 305 ~ getInitData ~ err",
            err
          );
        });
    },

    handleDelUpload(proofId) {
      this.$confirm("您确认要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteListProofs({ proof_ids: proofId })
          .then(({ success, message }) => {
            success
              ? this.$message.success(message)
              : this.$message.error(message);
            this.getInspectProofs();
          })
          .catch((err) => {
            console.log(
              "🚀 ~ file: sign.vue ~ line 305 ~ getInitData ~ err",
              err
            );
          });
      });
    },
    // 下载
    handleDownload(link) {
      const name = link.substring(link.lastIndexOf("/") + 1);
      const a_link = document.createElement("a"); // 生成一个a链接
      fetch(link) // 括号里是文件链接
        .then((res) => res.blob())
        .then((blob) => {
          // 将链接地址字符内容转变成blob地址
          a_link.href = URL.createObjectURL(blob);
          console.log(a_link.href);
          a_link.download = name; //下载的文件的名字
          document.body.appendChild(a_link);
          a_link.click();
        });
    },

    getInitData(detailId) {
      findByPlanDetailId({ detailId: detailId })
        .then(({ data }) => {
          const { chargePerson, linkTelephone, rawPersonName, unitName } = data;
          const metLpInspect = data.metLpInspect;
          for (const key in metLpInspect) {
            if (metLpInspect[key] === "0" || metLpInspect[key] === "1") {
              metLpInspect[key] = parseInt(metLpInspect[key]);
              metLpInspect.lpProblemLevel = parseInt(
                metLpInspect.lpProblemLevel
              );
            }
            this.form[key] = metLpInspect[key];
          }
          this.inspectId = data.inspectId;
          this.form.chargePerson = chargePerson;
          this.form.linkTelephone = linkTelephone;
          this.form.rawPersonName = rawPersonName;
          this.form.unitName = unitName;
        })
        .catch((err) => {
          console.log(
            "🚀 ~ file: sign.vue ~ line 305 ~ getInitData ~ err",
            err
          );
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.iframe-main {
  width: 100%;
  display: flex;
  justify-content: center;
  background: #fff;
  margin: 0 auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  .iframe {
    height: calc(100vh - 110px);
  }
  .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
  }
}
.main {
  width: 100%;
  .table-main {
    width: 760px;
    background: #fff;
    padding: 20px;
    box-sizing: border-box;
    margin: 0 auto;
  }
}

.iframe {
  height: calc(100vh - 50px);
}
.flexEnd {
  display: flex;
  flex-direction: column;
  align-items: end;
}

.tableName {
  font-weight: bold;
  font-size: 20px;
  width: 100%;
  text-align: center;
  margin-bottom: 8px;
}
.sub-tableName {
  margin-bottom: 16px;
  display: flex;
  width: 100%;
  justify-content: space-between;
  font-size: 14px;
  align-items: center;
  .No {
    display: flex;
    width: 250px;
    margin-left: 16px;
    align-items: center;
    span {
      white-space: nowrap;
    }
    ::v-deep .el-input__inner {
      border: none;
      // border-radius: 0;
    }
  }
}
.foot-table {
  display: flex;
  width: 100%;
  font-size: 14px;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  > div {
    display: flex;
    margin-left: 16px;
    align-items: center;
    flex: 1;
    span {
      white-space: nowrap;
    }
    ::v-deep .el-input__inner {
      border: none;
      // border-radius: 0;
    }
  }
}
.table {
  width: 100%;
  border: 1px solid #f2f2f2;
  tr {
    td {
      border: 1px solid #f2f2f2;
      color: #555;
      min-width: 120px;
      font-size: 14px;
      &.text {
        padding: 0 12px;
      }
    }
  }
  .radio-group {
    height: 40px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-around;
  }
  ::v-deep .el-input__inner {
    border: none;
    // border-radius: 0;
  }
  ::v-deep .el-textarea__inner {
    border: none;
  }
  ::v-deep .el-input.is-disabled .el-input__inner {
    background: #fff;
  }
  ::v-deep .el-textarea.is-disabled .el-textarea__inner {
    background: #fff;
  }
  ::v-deep.el-radio__input.is-disabled.is-checked .el-radio__inner {
    border-color: #409eff;
    background: #409eff;
  }
}

.search-user-list {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.upload {
  display: flex;
  justify-content: center;
  > div {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
